import { queryUserList } from '@/pages/user/services';

export default {
  namespace: 'userList',
  state: {
    list: [],
    page: {
      pageNo: 1,
      pageSize: 10,
      total: 0,
    },
  },
  effects: {
    // @ts-ignore
    *queryList({ payload }, { call, put }) {
      // @ts-ignore
      const response = yield call(queryUserList, payload);
      const { data, message, success, ...reset } = response || {};
      if (success) {
        yield put({ type: 'updateUserList', data: data });
        yield put({ type: 'updatePageNation', page: reset });
      } else {
        yield put({ type: 'updateUserList', data: [] });
      }
    },
  },
  reducers: {
    // @ts-ignore
    updateUserList(state: any, { data }) {
      return {
        ...state,
        list: data,
      };
    },
    updatePageNation(state: any, { page }: any) {
      return {
        ...state,
        page,
      };
    },
  },
};
